<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>后台管理登陆</title>
  <script src="https://www.layuicdn.com/auto/layui.js" v="2.5.6" e="layui"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js"></script>
  <link href="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/mobile/need/layer.css" rel="stylesheet">
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="view/static/js/jquerysession.js"></script>
  <link rel="stylesheet" href="view/static/css/login.css">
</head>

<body id="login">

<div class="login">
  <h2> <strong><font face="仿宋" >健身房后台管理登陆</font></strong></h2>
    <div class="layui-form-item">
      <input type="text" name="aname"  id="aname" placeholder="账号" class="layui-input" required>
      <i class="layui-icon input-icon">&#xe66f;</i>
    </div>

    <div class="layui-form-item">
      <input type="password" name="pwd" id="pwd" placeholder="密码"  class="layui-input" required>
      <i class="layui-icon input-icon">&#xe673;</i>
    </div>
  <form action="" class="layui-form">
  <div class="layui-form-item">
    <div class="layui-inline">
    <div class="layui-input-inline">
    <label ><input type="radio" name="xv" id="name_1" value="管理员" title="管理员" ></label>
    <label><input type="radio" name="xv"  id="name_2" value="用户" title="用户"></label>
    </div>
    </div>
  </div>
  </form>
  <div class="layui-form-item">
    <button type="button" style="width: 100%" class="layui-btn layui-btn-radius layui-btn-normal" lay-submit lay-filter="btn" id="btn">立即登录</button>
  </div>
  <p style="font-size: 0.8rem; margin-top: -0.3rem; text-align: right; color: red; position: absolute" id="adminLoginInfo"></p>
    <div class="layui-an">
    <a href="view/register.html" id="zhuce">还没有账号？点击注册</a>
    </div>
    <br>
    <div>
      <p style="font-family: 仿宋;color: #6f6e6e">ps:如忘记密码,请尽快联系管理人员更正密码</p>
    </div>
</div>



<script>
  layui.use(['layer', 'form'], function() {
    var layer = layui.layer;
    var form = layui.form;
    form.render('input')



//监听登录按钮
    $("#btn").click(function () {
      var item = $('input[name="xv"]:checked').val();
      var aname = $("#aname").val();
      var pwd = $("#pwd").val();
      if (aname == '') {
        $("#adminLoginInfo").text("提示：账号不能为空！");
      } else if (pwd == '') {
        $("#adminLoginInfo").text("提示：密码不能为空！");
      } else if (item == '管理员') {
        $.ajax({
          type: "post",
          url: "/admin/find",
          data: {
            aname: aname,
            pwd: pwd
          },
          dateType: "json",
          success: function (data) {
            if (data.trim() === "0") {
              $("#adminLoginInfo").text("提示：账号或密码错误");
            } else if (data.trim() === "1") {
              $("#adminLoginInfo").text("提示登陆成功");
              window.location.href = "view/admin_index.html";
            }
          }
        })
      }else if (item =='用户'){
        $.ajax({
          type: "post",
          url: "/user/finduser",
          data: {
            uname: aname,
            upwd: pwd,
          },
          dateType: "json",
          success: function (data) {
            $.session.set("uname",aname);
            if (data.trim() === "0") {
              $("#adminLoginInfo").text("提示：账号或密码错误");
            } else if (data.trim() === "1") {
              $("#adminLoginInfo").text("提示登陆成功");
              window.location.href = "view/user_index.html";
            }
          }
        })
      }
    })



  })

</script>
</body>

</html>
